package com.ruoyi.web.controller.common;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.service.impl.ResourceReadService;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/resource")
public class ResourceController {
    private final ResourceReadService resourceReadService;

    public ResourceController(ResourceReadService resourceReadService) {
        this.resourceReadService = resourceReadService;
    }

    @GetMapping("/video/{fileName:.+}")
    public AjaxResult getVideoView(@PathVariable String fileName) throws IOException {
        String resource = resourceReadService.readFileByResource(fileName);
        return AjaxResult.success(resource);
    }

    @GetMapping("/video")
    public AjaxResult getVideoViewParams(@RequestParam String fileName) throws IOException {
        String resource = resourceReadService.readFileByResource(fileName);
        return AjaxResult.success(resource);
    }
}
